{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-02-23T08:34:08.495Z",
     "start_time": "2024-02-23T08:34:08.491161Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------\n"
     ]
    }
   ],
   "source": [
    "# if语句\n",
    "# if False:\n",
    "if True:\n",
    "    print(\"成立\")\n",
    "    print(\"成立2\")\n",
    "print(\"------\")"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "不成立\n",
      "-------\n"
     ]
    }
   ],
   "source": [
    "# if True:\n",
    "if False:\n",
    "    print(\"成立\")\n",
    "else:\n",
    "    print(\"不成立\")\n",
    "print(\"-------\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-23T08:36:33.754827Z",
     "start_time": "2024-02-23T08:36:33.748550Z"
    }
   },
   "id": "251f81da5d20d49",
   "execution_count": 8
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number是偶数\n"
     ]
    }
   ],
   "source": [
    "number = 10\n",
    "if number % 2 == 1:\n",
    "    print(\"number是奇数\")\n",
    "elif number % 2 == 0:\n",
    "    print(\"number是偶数\")\n",
    "else:\n",
    "    print(f\"number的值是{number}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-23T08:39:50.168945Z",
     "start_time": "2024-02-23T08:39:50.164913Z"
    }
   },
   "id": "c1a59a84f430eb3f",
   "execution_count": 9
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "79是不能被3整除79\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "number = int(random.random() * 100 + 1)\n",
    "if number % 3 == 0:\n",
    "    print(f\"{number}是能被3整除\")\n",
    "elif number % 3 == 1:\n",
    "    print(f\"{number}是不能被3整除{number}\")\n",
    "else:\n",
    "    pass"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-23T08:44:34.804563Z",
     "start_time": "2024-02-23T08:44:34.800094Z"
    }
   },
   "id": "d11a9b5a8cb8a797",
   "execution_count": 17
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "猜数字游戏开始！\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "恭喜，你猜中了\n"
     ]
    }
   ],
   "source": [
    "# 猜数字游戏 （思考一下大家有没有更好的思路来完成）\n",
    "number = 7\n",
    "guess = -1\n",
    "print(\"猜数字游戏开始！\")\n",
    "while guess != number:\n",
    "    guess = int(input(\"请输入你猜的数字：\"))\n",
    "    if guess == number:\n",
    "        print(\"恭喜，你猜中了\")\n",
    "    elif guess < number:\n",
    "        print(\"猜的数字小了\")  \n",
    "    else:\n",
    "        print(\"猜的数字大了\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-01T06:54:08.171638Z",
     "start_time": "2024-03-01T06:53:27.188190Z"
    }
   },
   "id": "769a6dca2670a419",
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "猜的数字小了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "猜的数字大了\n",
      "恭喜，你猜中了\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "number = random.randint(1, 10)\n",
    "guess = -1\n",
    "while guess != number:\n",
    "    guess = int(input(\"请输入你猜的数字：\"))\n",
    "    if guess == number:\n",
    "        print(\"恭喜，你猜中了\")\n",
    "    elif guess < number:\n",
    "        print(\"猜的数字小了\")  \n",
    "    else:\n",
    "        print(\"猜的数字大了\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-03-01T06:59:17.456203Z",
     "start_time": "2024-03-01T06:58:44.413902Z"
    }
   },
   "id": "86dabc270efd0ee7",
   "execution_count": 7
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "d7778aaaa9c7a1d5"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
